package com.yuanguangsheng.disk.spring.security;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;

@Component
public class GdmtPasswordEncoder implements PasswordEncoder {
    @Value("${passwd.key}")
    private String passwdKey;
    @Override
    public String encode(CharSequence rawPassword) {
        return DigestUtils.md5DigestAsHex((rawPassword + passwdKey).getBytes());
    }

    @Override
    public boolean matches(CharSequence charSequence, String s) {
        return s.equals(encode(charSequence.toString()));
    }

}
